<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" inline label-width="80px">
      <el-form-item prop="searchValue">
        <el-input
          v-model="queryParams.searchValue"
          placeholder="请输入关键字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="areaId">
        <el-select
          v-model="queryParams.areaId"
          style="width: 100%"
          placeholder="请选择区域"
        >
          <el-option v-for="(i, k) in areaList" :key="k" :label="i.name" :value="i.id" />
        </el-select>
      </el-form-item>
      <el-form-item prop="type">
        <el-radio-group v-model="queryParams.type" size="small">
          <el-radio-button v-for="(i, k) in typeList" :key="k" :label="i.value">
            {{ i.label }}
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">
          查询
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" border :data="dataList">
      <el-table-column label="用户名" align="center" prop="nickName" />
      <el-table-column label="配置标题" align="center" prop="serverName" />
      <el-table-column label="订单配置" align="center" prop="orderAbstract" />
      <el-table-column label="计费模式" align="center" prop="periodType">
        <template slot-scope="scope">
          <span>{{ scope.row.periodType | ctChargeType }}</span>
        </template>
      </el-table-column>
      <el-table-column label="金额" align="center" prop="updatePrice" />
      <el-table-column label="下单时间" align="center" prop="createTime" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { govAreaList } from "@/api/system/config";
import { listGovernmentCloud } from "@/api/productManagement/governmentCloud";

export default {
  data() {
    return {
      loading: false, // 遮罩层
      total: 0, // 总条数
      dataList: [], // 费用中心表格数据
      typeList: [
        { value: null, label: "全部" },
        { value: "cpu", label: "CPU" },
        { value: "memory", label: "内存" },
        { value: "hardDisk", label: "硬盘" },
        { value: "defense", label: "防御" },
        { value: "bandwidth", label: "带宽" },
        { value: "ip", label: "IP" },
      ],
      areaList: [], // 区域列表
      // 查询参数
      queryParams: {
        searchValue: null, //关键字查询
        areaId: null, // 区域id
        type: null,
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getAreaList();
    this.getList();
  },
  methods: {
    /** 查询政务云列表 */
    getList() {
      this.loading = true;
      listGovernmentCloud(this.queryParams)
        .then((res) => {
          this.dataList = res.rows;
          this.total = res.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 查询区域列表
    getAreaList() {
      govAreaList().then((res) => {
        this.areaList = res.data;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
